﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UIWindows.Models.Devices;
using UIWindows.Tools.Helper;
using XingLucifer.IBase.Enums;

namespace UIWindows.Views
{
    /// <summary>
    /// ElectricityStatement.xaml 的交互逻辑
    /// </summary>
    //[Attributes.ViewFeature("电能表统计", 4, true, Enums.AuthorityTypes.ALL, MaterialDesignThemes.Wpf.PackIconKind.BatteryChargingOutline)]
    public partial class ElectricityStatement : UserControl
    {
        public ElectricityStatement()
        {
            InitializeComponent();
        }

        //#region 私有方法
        //private float GetValue(DeviceClientModel com)
        //{
        //    Stopwatch stoptimeout = new Stopwatch();
        //    List<byte> bytes = new List<byte>();
        //    var cmd = new byte[] { 0x01, 0x03, 0x10, 0x1E, 0x00, 0x02, 0xA0, 0xCD };//读取正向有功总电能
        //    com.Communication.WriteSingle(cmd, cmd.Length);
        //    while (true)
        //    {
        //        if (stoptimeout.ElapsedMilliseconds == 3000)
        //        {
        //            $"电能表 获取数据超时!!!".RunLog(MessageLevelType.警告);
        //            Thread.Sleep(1000);
        //            break;
        //        }
        //        bytes.AddRange(com.Communication.Read(9));
        //        if (bytes.Count >= 2 && bytes[0] == 0x01 && bytes[1] == 0x03 && bytes.Count == 9)
        //        {
        //            break;
        //        }
        //        Thread.Sleep(50);
        //    }
        //    if (bytes.Count != 9)
        //    {
        //        return 0;
        //    }
        //    return BitConverter.ToSingle(bytes.Skip(3).Take(4).Reverse().ToArray());
        //}

        //private bool ClrE(DeviceClientModel com)
        //{
        //    List<byte> bytes = new List<byte>();
        //    Stopwatch stoptimeout = new Stopwatch();
        //    //返回 01 10 00 02 00 01 a0 09 f3 
        //    var cmd = new byte[] { 0x01, 0x10, 0x00, 0x02, 0x00, 0x01, 0x02, 0x00, 0x01, 0x66, 0x72 };
        //    com.Communication.WriteSingle(cmd, cmd.Length);
        //    while (true)
        //    {
        //        if (stoptimeout.ElapsedMilliseconds == 3000)
        //        {
        //            $"电能表 清零数据超时!!!".RunLog(MessageLevelType.警告);
        //            Thread.Sleep(1000);
        //            return false;
        //        }
        //        bytes.AddRange(com.Communication.Read(11));
        //        if (bytes.Count >= 2 && bytes[0] == 0x01 && bytes[1] == 0x03 && bytes.Count == 11)
        //        {
        //            return true;
        //        }
        //        Thread.Sleep(50);
        //    }
        //}
        //#endregion
    }
}
